﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Item.Master" AutoEventWireup="true"
    CodeBehind="SelectHelpPopup.aspx.cs" Inherits="SGDemo.Permission.SelectHelpPopup" %>

<asp:Content ID="Content1" ContentPlaceHolderID="cpHeader" runat="server">
    <style type="text/css">
        .ui-select-content
        {
            overflow: hidden;
            padding-top: 15px;
        }
        .ui-select-primary
        {
            width: 600px;
            float: left;
            min-height: 300px;
        }
        .ui-select-secondary
        {
            width: 260px;
            float: right;
            min-height: 300px;
            background-color: Gray;
        }
        .ui-select-operation
        {
            height: 30px;
            padding: 10px;
        }
        .clear
        {
            clear: both;
        }
        .ui-select-operation table
        {
            width: 100%;
        }
        .ui-select-operation table td
        {
            text-align: center;
        }
    </style>
    <script type="text/javascript">
        //当前窗口
        var Shadowbox = window.parent.Shadowbox;
        //控件集合实例
        var controlsCollection;

        $(document).ready(function () {
            var collection = [
                New(ASPxRFTextBox, ['txtTitle', ['GroupA'], 'Title']),
                New(ASPxRFTextBox, ['txtHelpCode', ['GroupA'], 'HelpCode']),
                New(ASPxRFComboBox, ['cbHelpCategoryKeyid', ['GroupA'], { valueField: 'HelpCategoryKeyid'}])
            ];
            controlsCollection = New(RapidForm, [collection]);
        });

        //刷新
        var doRefresh = function () {
            $('#hfFilterCondition').val(' ');
            gvwList.PerformCallback();
        }
        //GridView选中全部或者取消选中全部
        var doSelectOrUnselectAll = function (s, e) {
            gvwList.SelectAllRowsOnPage(s.GetChecked());
        }
        //执行查找
        var doSubmittedToSearch = function () {
            $('#hfFilterCondition').val(controlsCollection.getQueryString('GroupA'));
            gvwList.PerformCallback();
        }
        //重置
        var doResetToSearch = function () {
            controlsCollection.reset('GroupA');
        }
        //关闭当前按钮
        var doClose = function () {
            Shadowbox.close();
        }
        var doSelectionChanged = function (s, e) {
            //1,当前页全选
            //2,手动选择
            if (e.isAllRecordsOnPage) {

            } else {
                if (e.isSelected) {
                    s.GetRowValues(e.visibleIndex, 'Keyid;HelpCode;Title', doGetRowValues);
                } else {
                    s.GetRowValues(e.visibleIndex, 'Keyid;HelpCode;Title', doRemoveRowValues);
                }
            }
        }
        var doGetRowValues = function (values) {
            if (Shadowbox.selectionMode == 'Single') {
                lbSelectedItems.ClearItems();
                lbSelectedItems.BeginUpdate();
                index = lbSelectedItems.AddItem(values[2], values[0]);
                lbSelectedItems.SelectAll();
                lbSelectedItems.EndUpdate();
            } else {
                lbSelectedItems.BeginUpdate();
                var index = lbSelectedItems.AddItem(values[2], values[0]);
                lbSelectedItems.SelectAll();
                lbSelectedItems.EndUpdate();
            }
        }
        var doRemoveRowValues = function (values) {
            var count = lbSelectedItems.GetItemCount();
            if (count > 0) {
                var index = lbSelectedItems.FindItemByValue(values[0]).index;
                if (index >= 0) {
                    lbSelectedItems.BeginUpdate();
                    lbSelectedItems.RemoveItem(index);
                    lbSelectedItems.EndUpdate();
                }
            }
        }

        var doCancelSelect = function (s, e) {
            if (!e.isSelected) {
                //取消Grid对应项选中
                var keyid = lbSelectedItems.GetItem(e.index).value;
                gvwList.UnselectRowsByKey(keyid);
                //移除Listbox选中项
                lbSelectedItems.BeginUpdate();
                lbSelectedItems.RemoveItem(e.index);
                lbSelectedItems.EndUpdate();
            }
        }

        //确定
        var doSubmittedToSelect = function () {
            gvwList.GetSelectedFieldValues(Shadowbox.returnFields, doGetSelectedFieldValues);
        }

        var doGetSelectedFieldValues = function (selectedValues) {
            if (selectedValues.length == 0) {
                if (Shadowbox.compeleteFn) {
                    parent.window[Shadowbox.compeleteFn](null);
                }
            } else {
                if (Shadowbox.compeleteFn) {
                    parent.window[Shadowbox.compeleteFn](selectedValues);
                }
            }
            Shadowbox.close();
        }

        //清空
        var doClearToSelect = function () {
            gvwList.UnselectRows();
            lbSelectedItems.ClearItems();
        }

        //关闭
        var doCloseToSelect = function () {
            Shadowbox.close();
        }

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpBody" runat="server">
    <div style="width: 900px">
        <dx:ASPxRoundPanel ID="rpRole" runat="server" Width="100%" HeaderText="查询条件" Font-Bold="true"
            EnableViewState="false">
            <PanelCollection>
                <dx:PanelContent>
                    <div>
                        <ul class="ui-list">
                            <li>
                                <dx:ASPxLabel ID="ASPxLabel1" runat="server" Text="帮助主题：" AssociatedControlID="txtTitle" />
                            </li>
                            <li>
                                <dx:ASPxTextBox ID="txtTitle" ClientInstanceName="txtTitle" runat="server" Width="120px">
                                </dx:ASPxTextBox>
                            </li>
                            <li>
                                <dx:ASPxLabel ID="ASPxLabel2" runat="server" Text="帮助编码：" AssociatedControlID="txtHelpCode" />
                            </li>
                            <li>
                                <dx:ASPxTextBox ID="txtHelpCode" ClientInstanceName="txtHelpCode" runat="server"
                                    Width="120px">
                                </dx:ASPxTextBox>
                            </li>
                            <li>
                                <dx:ASPxLabel ID="lblDeptCategorykeyd" runat="server" Text="帮助类别：" AssociatedControlID="cbDeptType" />
                            </li>
                            <li>
                                <dx:ASPxComboBox ID="cbHelpCategoryKeyid" ClientInstanceName="cbHelpCategoryKeyid"
                                    runat="server" Width="120">
                                </dx:ASPxComboBox>
                            </li>
                        </ul>
                        <ul class="sl-floatcenter clearfix">
                            <li class="sl-floatcenter-item">
                                <dx:ASPxButton ID="btnSubmit" ClientInstanceName="btnSubmit" runat="server" Text="查 询"
                                    AutoPostBack="false">
                                    <ClientSideEvents Click="doSubmittedToSearch" />
                                </dx:ASPxButton>
                            </li>
                            <li class="sl-floatcenter-item">
                                <dx:ASPxButton ID="btnReset" ClientInstanceName="btnReset" runat="server" Text="重 置"
                                    AutoPostBack="false">
                                    <ClientSideEvents Click="doResetToSearch" />
                                </dx:ASPxButton>
                            </li>
                        </ul>
                    </div>
                </dx:PanelContent>
            </PanelCollection>
        </dx:ASPxRoundPanel>
        <dx:ASPxRoundPanel ID="ASPxRoundPanel1" runat="server" Width="100%" HeaderText="结果列表"
            Font-Bold="true" EnableViewState="false">
            <PanelCollection>
                <dx:PanelContent>
                    <div class="ui-select-content">
                        <div class="ui-select-primary">
                            <%--gvwList--%>
                            <dx:ASPxGridView ID="gvwList" ClientInstanceName="gvwList" runat="server" AutoGenerateColumns="False"
                                DataSourceID="odsList" Width="100%" KeyFieldName="Keyid" OnCustomCallback="gvwList_CustomCallback">
                                <Columns>
                                    <dx:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0" HeaderStyle-HorizontalAlign="Center"
                                        Width="40">
                                        <%--<HeaderTemplate>
                                            <dx:ASPxCheckBox ID="cbSelectAll" runat="server">
                                                <ClientSideEvents CheckedChanged="doSelectOrUnselectAll" />
                                            </dx:ASPxCheckBox>
                                        </HeaderTemplate>--%>
                                    </dx:GridViewCommandColumn>
                                    <dx:GridViewDataColumn Caption="帮助主题" FieldName="Title" VisibleIndex="1" Width="180">
                                    </dx:GridViewDataColumn>
                                    <dx:GridViewDataColumn Caption="帮助编码" FieldName="HelpCode" VisibleIndex="2" Width="80">
                                    </dx:GridViewDataColumn>
                                    <dx:GridViewDataColumn Caption="帮助类别" FieldName="HelpCategoryName" VisibleIndex="3"
                                        Width="80">
                                    </dx:GridViewDataColumn>
                                </Columns>
                                <SettingsBehavior AllowFocusedRow="true" />
                                <SettingsLoadingPanel Text="加载中..." />
                                <SettingsPager PageSize="10" Mode="ShowPager" Summary-Text="当前第{0}页，共{1}页(共{2}条)">
                                </SettingsPager>
                                <SettingsText EmptyDataRow="没有数据显示" />
                                <ClientSideEvents SelectionChanged="doSelectionChanged" />
                            </dx:ASPxGridView>
                            <%--数据源控件--%>
                            <asp:ObjectDataSource ID="odsList" runat="server" SelectMethod="FilteredGetAll" TypeName="SGDemo.Permission.HelpDataSource">
                                <SelectParameters>
                                    <asp:ControlParameter Name="filterConditions" Type="String" ControlID="hfFilterCondition"
                                        PropertyName="Value" ConvertEmptyStringToNull="false" />
                                </SelectParameters>
                            </asp:ObjectDataSource>
                            <%--存储过滤条件--%>
                            <asp:HiddenField ID="hfFilterCondition" ClientIDMode="Static" runat="server" Value=" " />
                        </div>
                        <div class="ui-select-secondary">
                            <dx:ASPxListBox ID="lbSelectedItems" runat="server" ClientInstanceName="lbSelectedItems"
                                Width="258px" Height="300" SelectionMode="CheckColumn">
                                <ClientSideEvents SelectedIndexChanged="doCancelSelect"></ClientSideEvents>
                            </dx:ASPxListBox>
                        </div>
                        <div class="clear">
                        </div>
                    </div>
                </dx:PanelContent>
            </PanelCollection>
        </dx:ASPxRoundPanel>
        <dx:ASPxRoundPanel ID="rpt3" runat="server" Width="100%" HeaderText="操作" Font-Bold="true"
            EnableViewState="false">
            <PanelCollection>
                <dx:PanelContent>
                    <div class="ui-select-operation">
                        <table cellpadding="0" cellspacing="0" border="0">
                            <tr>
                                <td>
                                    <dx:ASPxButton ID="ASPxButton1" ClientInstanceName="btnSubmit" runat="server" Text="确 定"
                                        AutoPostBack="false" Width="50">
                                        <ClientSideEvents Click="doSubmittedToSelect" />
                                    </dx:ASPxButton>
                                </td>
                                <td>
                                    <dx:ASPxButton ID="ASPxButton2" ClientInstanceName="btnReset" runat="server" Text="清 空"
                                        AutoPostBack="false" Width="50">
                                        <ClientSideEvents Click="doClearToSelect" />
                                    </dx:ASPxButton>
                                </td>
                                <td>
                                    <dx:ASPxButton ID="btnClose" ClientInstanceName="btnClose" runat="server" Text="关 闭"
                                        AutoPostBack="false" Width="50">
                                        <ClientSideEvents Click="doCloseToSelect" />
                                    </dx:ASPxButton>
                                </td>
                            </tr>
                        </table>
                    </div>
                </dx:PanelContent>
            </PanelCollection>
        </dx:ASPxRoundPanel>
    </div>
</asp:Content>
